/**
 * 
 */
package com.gr.staffpm.pages.tasks.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;

import com.gr.staffpm.gof.observer.Subscribable;
import com.gr.staffpm.gof.observer.Subscriber;


/**
 * @author Graham Rhodes 1 Jan 2011 19:43:59
 */
public abstract class AbstractAjaxTaskLink extends AjaxLink<Void> implements Subscribable {

    private static final long serialVersionUID = 1L;
    private final List<Subscriber> subscriptions = new ArrayList<Subscriber>();

    public AbstractAjaxTaskLink(String id, Subscriber subscriber) {
        super(id);
        addSubscriber(subscriber);
    }

    /* (non-Javadoc)
     * @see org.apache.wicket.ajax.markup.html.AjaxLink#onClick(org.apache.wicket.ajax.AjaxRequestTarget)
     */
    @Override
    public abstract void onClick(AjaxRequestTarget target);

    /* (non-Javadoc)
     * @see com.gr.staffpm.gof.observer.subscribable.ISubscribable#addSubscriber(com.gr.staffpm.gof.observer.subscriber.ISubscriber)
     */
    @Override
    public void addSubscriber(Subscriber subscriber) {
        subscriptions.add(subscriber);
    }

    /* (non-Javadoc)
     * @see com.gr.staffpm.gof.observer.subscribable.ISubscribable#notifySubscribers(java.lang.Object)
     */
    @Override
    public void notifySubscribers(Object obj, AjaxRequestTarget target) {
        for (Subscriber subscriber : subscriptions)
            subscriber.notifySubscriber(obj, target);
    }

}
